/**
 * 已发货
*/

var deliver_shipped = new Object({
    table:null,
    init:function(){
        if(null != this.table)
            return;
        //console.info("init ok...")
        this.queryList();
    },
    queryList:function(){
        this.table = $('#tb_deliver_shipped').bootstrapTable({
            url: contextPath + '/deliver/listData.json',
            responseHandler: function (res) {
                return res.data;
            },
            queryParams: function (params) {
                params.deliverStartDate = $('#deliverStartDate').val();
                params.deliverStopDate = $('#deliverStopDate').val();
                params.status =  4;
                return params;
            },
            pagination: true,
            pageList: '[10,20, 50, 100]',
            //showColumns: true,
            showRefresh: true,
            showToggle: true,
            //showPaginationSwitch:true,
            sidePagination: 'server',
            //striped:true,
            sortable: false,
            height: 700,
            search: true,
            searchAlign: 'left',
            toolbar: '' +
            '<div style="float:left;display: inline-flex;">' +
            '       <label style="display:inline;">时间范围：</label>' +
            '       <div class="input-daterange input-group" id="shipped-datepicker-range">' +
            '           <input class="form-control" type="text" id="deliverStartDate" placeholder="开始时间" />' +
            '           <span class="input-group-addon" style="width:10px;">to</span>' +
            '           <input class="form-control" type="text" id="deliverStopDate" placeholder="结束时间" />' +
            '       </div>' +
            '</div>' +
            '<div style="float: left;margin-right:5px;">' +
            '    <button class="btn btn-default" type="button" onclick="deliver_shipped.doSearch()">' +
            '        <i style="margin-right:2px;" class="fa fa-search"></i>' +
            '        <span>查询</span>' +
            '    </button>' +
            '</div>',
            idField: 'id',
            uniqueId: 'id',
            //singleSelect: true,
            clickToSelect: true,
            columns: [{
                field: 'id',
                title: 'ID',
                width: 100,
                visible:false
            }, {
                field: 'applyTime',
                title: '申请时间',
                width: 100,
                formatter:function(value,row,index){
                    return (new Date(value)).Format("yyyy-MM-dd hh:mm");
                }
            }, {
                field: 'auditTime',
                title: '审核时间',
                width: 100,
                formatter:function(value,row,index){
                    return (new Date(value)).Format("yyyy-MM-dd hh:mm");
                }
            }, {
                field: 'player.nickname',
                title: '微信昵称',
                width: 60
            }, {
                field: 'playerAddress.consignee',
                title: '收货人',
                width: 100
            }, {
                field: 'playerAddress.consigneeTel',
                title: '收货电话',
                width: 100
            }, {
                field: 'playerAddress.province',
                title: '省',
                width: 70
            }, {
                field: 'playerAddress.city',
                title: '市',
                width: 70
            }, {
                field: 'playerAddress.district',
                title: '区',
                width: 70
            }, {
                field: 'playerAddress.address',
                title: '详细地址',
                width: 150
            }, {
                field: 'deliverCorp',
                title: '快递公司',
                width: 70
            }, {
                field: 'deliverCode',
                title: '快递单号',
                width: 100
            }, {
                field: 'status',
                title: '状态',
                width: 50,
                formatter:function(value,row,index){
                    switch(value){
                        case 1:
                            return '待审核'
                        case 2:
                            return '待发货'
                        case 4:
                            return '已发货'
                    }
                }
            }, {
                field: 'deliverTime',
                title: '发货时间',
                width: 100,
                formatter:function(value,row,index){
                    return (new Date(value)).Format("yyyy-MM-dd hh:mm");
                }
            }, {
                field: 'op',
                title: '操作',
                width: 60,
                formatter: function (value, row, index) {
                    var strHtml = '';
                    strHtml += '<button type="button" class="btn btn-default" onclick="deliver_shipped.showDetail(' + row.id + ')">配送明细</button>&nbsp;&nbsp;';
                    return strHtml;
                }
            }]
        });
        $('.search input').attr("placeholder", "微信昵称 | 收货人");
        deliver_shipped.loadDatePicker();
    },
    doSearch:function(){
        deliver_shipped.table.bootstrapTable('refresh');
    },
    loadDatePicker:function(){
        //日期控件加载
        var options = {
            orientation: $('body').hasClass('right-to-left') ? "auto right" : 'auto auto',
            todayBtn: "linked",
            format: 'yyyy-mm-dd',
            language: 'zh-CN',
            clearBtn: true,
            autoclose: true
        };
        $('#shipped-datepicker-range').datepicker(options);
    },
    showDetail: function (id) {
        var detailModal = '' +
            '<div id="detailModal" class="modal fade" tabindex="-1" role="dialog" style="display: none;">' +
            '   <div class="modal-dialog">' +
            '       <div class="modal-content">' +
            '           <div class="modal-header">' +
            '               <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>' +
            '               <h4 class="modal-title">配送明细</h4>' +
            '           </div>' +
            '           <div class="modal-body">' +
            '               <table class="table-primary" id="detailTable"></table>' +
            '           </div>' +
            '           <div class="modal-footer">' +
            '               <center>' +
            '                   <button class="btn btn-primary" type="button" data-dismiss="modal" aria-hidden="true">关闭</button>' +
            '               </center>' +
            '           </div>' +
            '       </div>' +
            '   </div>' +
            '</div>';

        document.body.appendChild($(detailModal)[0]);
        $('#detailModal').on('hidden.bs.modal', function () {
            document.body.removeChild($('#detailModal')[0]);
        });

        $('#detailTable').bootstrapTable({
            url: contextPath + '/deliver/' + id + '/detail/listData.json',
            responseHandler: function (res) {
                return res.data;
            },
            queryParams: function (params) {
                return params;
            },
            pagination: false,
            //pageList: '[10,20, 50, 100]',
            //showColumns: true,
            showRefresh: true,
            showToggle: true,
            //showPaginationSwitch:true,
            sidePagination: 'server',
            //striped:true,
            sortable: false,
            height: 700,
            search: false,
            searchAlign: 'left',
            idField: 'id',
            uniqueId: 'id',
            //singleSelect: true,
            clickToSelect: true,
            columns: [{
                field: 'id',
                title: 'ID',
                width: 100,
                visible: false
            }, {
                field: 'waWaType.typeName',
                title: '娃娃类型名称',
                width: 100
            }, {
                field: 'waWaType.typeCode',
                title: '娃娃类型编码',
                width: 100
            }]
        });
        //显示
        $("#detailModal").modal('show')
    }
});